function ProductViewCtrl($rootScope, $scope, $http, $routeParams) {
	var url = DOMAIN + "/data/product";
	$scope.itemId = $routeParams.id;
	$scope.item = {};
	
	$scope.getItem = function() {
		$http.get(url + '/get/' + $scope.itemId).success(function(data) {
			$scope.item = data;
		});
	};
	
	// Initial
	$scope.getItem();
}

function ProductManageCtrl($rootScope, $scope, $http, $routeParams) {
	var url = DOMAIN + "/data/product";
	$scope.itemId = $routeParams.productId;
	$scope.items = [];
	$scope.item = {};

	$scope.getItems = function() {
		$http.post(url + '/gets').success(function(data) {
			$scope.items = data;
		});
	};

	$scope.addItem = function() {
		$http.post(url + '/add', $scope.item).success(function(data) {
			$scope.item.id = data;

			// Add to list view
			$scope.items.push($scope.item);

			$scope.resetItem();
		});
	};

	$scope.updateItem = function() {
		$http.post(url + '/update', $scope.item).success(function() {
			// Replace to list view
			replaceById($scope.items, $scope.item);

			$scope.resetItem();
		});
	};

	$scope.deleteItem = function() {
		$http.post(url + '/delete/' + $scope.item.id).success(
				function() {
					// Remove from list view
					deleteById($scope.items, $scope.item.id);

					$scope.resetItem();
				});
	};

	// Initial
	$scope.getItems();
}